<template>
	<view class="home">
		<!-- 自定义组件 -->
		<navbar></navbar>
		<tab :list="tabList" :tabIndex="tabIndex" @tab='tab'></tab>
		<view class="home-list">
			<list :tab="tabList" :activeIndex="activeIndex" @change="change"></list>
		</view>
	</view>
</template>

<script>
	// import tab from '@/components/tab/tab.vue';
	// import list from '@/components/list/list.vue';
	import { mapState } from 'vuex';	
	export default {
		data() {
			return {
				title: 'Hello',
				tabList: [],
				tabIndex: 0,
				activeIndex:0
			}
		},
		computed: {
			...mapState(['userinfo'])
		},
		watch: {
			userinfo(newValue) {
				this.getLabel();
			}
		},
		onLoad() {
			
			uni.$on('labelChange',(res) => {
				this.tabList = []
				this.tabIndex = 0
				this.activeIndex = 0
				this.getLabel()
			})
			
			//#ifndef H5
			let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
			console.log(menuButtonInfo);
			//#endif
		},
		methods: {
			tab({data,index}) {
				console.log(data, index);
				this.activeIndex = index
			},
			getLabel() {
				console.log(this.$Api);
				this.$Api.get_list().then((res) => {
					console.log(res);
				})
				this.$Api.get_label().then((res) => {
					const {data} = res;
					console.log("data: ",data);
					data.unshift({name:'全部'})
					this.tabList = data;
				})
			},
			change(current) {
				console.log('当前swiper的值', current);
				this.tabIndex = current
				// BUG
				this.activeIndex = current 
			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
		display: flex;
	}

	.home {
		display: flex;
		flex-direction: column;
		flex: 1;
		overflow: hidden;

		// border: 1px red solid;
		.home-list {
			flex: 1;
			box-sizing: border-box;
			// border: 1px red solid;
		}
	}
</style>
